package com.example.administrator.baikangxing.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.baikangxing.R;
import com.example.administrator.baikangxing.utils.ShareUtil;
import com.example.administrator.baikangxing.utils.ToastUtil;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;

public class ShareActivity extends BaseActivity implements View.OnClickListener {


    private ImageView share_iv_qq;
    private String titleurl = "http://www.baikangcn.com/";
    private String image_url = "http://www.baikangcn.com/upload/201611/26/201611261309227070.jpg";
    private ImageView share_iv_sina;
    private ImageView share_iv_wechat;
    private ImageView share_iv_wechatmoment;
    private TextView share_tv_cancel;

    @Override
    public int getContentViewLayoutId() {
        return R.layout.activity_share;
    }

    @Override
    public void initView() {
        setTitles("分享客户端");
        base_ib_menu.setVisibility(View.INVISIBLE);
        share_iv_sina = findView(R.id.share_iv_sina);
        share_iv_wechat = findView(R.id.share_iv_wechat);
        share_iv_wechatmoment = findView(R.id.share_iv_wechatmoment);
        share_iv_qq = findView(R.id.share_iv_qq);
        share_tv_cancel = findView(R.id.share_tv_cancel);
        share_iv_sina.setOnClickListener(this);
        share_tv_cancel.setOnClickListener(this);
        share_iv_qq.setOnClickListener(this);
        share_iv_wechat.setOnClickListener(this);
        share_iv_wechatmoment.setOnClickListener(this);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.share_iv_qq://分享qq
                ShareUtil.Builder.getInstanse(this).setPlatformActionListener(new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                        ToastUtil.showToast("分享成功");
                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        ToastUtil.showToast("分享失败");

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {
                        ToastUtil.showToast("分享取消");
                    }
                }).shareToQQ("百康星",titleurl,"这是一个分享连接",image_url);
                break;
            case R.id.share_iv_sina://分享新浪微博
                ShareUtil.Builder.getInstanse(this).setPlatformActionListener(new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                        ToastUtil.showToast("分享成功");
                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        ToastUtil.showToast("分享失败");

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {
                        ToastUtil.showToast("分享取消");
                    }
                }).shareToSina("百康星",image_url);
                break;
            case R.id.share_iv_wechat://分享微信
                ShareUtil.Builder.getInstanse(this).setPlatformActionListener(new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                        ToastUtil.showToast("分享成功");
                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        ToastUtil.showToast("分享失败");

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {
                        ToastUtil.showToast("分享取消");
                    }
                }).shareToWechat("百康星","欢迎使用百康星",image_url,titleurl);
                break;
            case R.id.share_iv_wechatmoment://分享微信朋友圈
                ShareUtil.Builder.getInstanse(this).setPlatformActionListener(new PlatformActionListener() {
                    @Override
                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                        ToastUtil.showToast("分享成功");
                    }

                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        ToastUtil.showToast("分享失败");

                    }

                    @Override
                    public void onCancel(Platform platform, int i) {
                        ToastUtil.showToast("分享取消");
                    }
                }).shareToWechatMoments("百康星","欢迎使用百康星",image_url,titleurl);
                break;
            case R.id.share_tv_cancel:
                finish();
                break;
            default:
                break;
        }
    }
}
